<?php

namespace App\Console\Commands;

use App\Models\ChallengeGame;
use Carbon\Carbon;
use Illuminate\Console\Command;

class CloseChallenge extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'batch:closechallenge';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '关闭挑战赛';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $limitFinish = Carbon::now()->subHour();
        $limitScore = Carbon::now()->subDay();
        //未输入比分，判定挑战者输
        ChallengeGame::where([['status', 10],
            ['game_datetime', '<', $limitScore]])
            ->update(['status' => 40,
                'score_a' => 0,
                'score_b' => 3]);
        //结算比赛
        ChallengeGame::where([['status', 20],
            ['game_datetime', '<', $limitFinish]])
            ->update(['status' => 40]);
        $this->info('执行成功');

    }
}
